using System.Linq;
using Headsight.BPMN2WF.Testing;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Headsight.BPMN2WF.WF.Impl
{
	[TestClass]
	public class ModelItemSoRTest
	{
		private Flowchart4TestHelper _fcBuilder;
		private ModelItemUtils _sut;

		[TestInitialize]
		public void SetUp()
		{
			_fcBuilder = new Flowchart4TestHelper();

			_sut = new ModelItemUtils(null, null);
		}

		[TestMethod]
		public void ImmediateChilds_Root()
		{
			_sut = new ModelItemUtils(_fcBuilder.Root, null);

		    var result = _sut.ImmediateChilds;

            Assert.AreEqual(1, result.Count);
            Assert.AreSame(_fcBuilder.Implementation, result[0]);
		}

        [TestMethod]
        public void ImmediateChilds_Implementation()
        {
            var startNode = _fcBuilder.CreateStartNode();

            _sut = new ModelItemUtils(_fcBuilder.Implementation, null);

            var result = _sut.ImmediateChilds;

            Assert.AreEqual(1, result.Count);
            Assert.AreSame(startNode, result[0]);
        }

        [TestMethod]
		public void ImmediateChilds_Next()
		{
            var startNode = _fcBuilder.CreateStartNode();
            var next = _fcBuilder.CreateNextNode();

            _sut = new ModelItemUtils(startNode, null);

            var result = _sut.ImmediateChilds;

            Assert.AreEqual(1, result.Count);
            Assert.AreSame(next, result[0]);
		}

        [TestMethod]
		public void ImmediateChilds_FlowDecision()
		{
            _fcBuilder.CreateStartNode();
            var nodes = _fcBuilder.CreateTrueAndFalse();

            _sut = new ModelItemUtils(nodes[0], null);

            var result = _sut.ImmediateChilds;

            Assert.AreEqual(2, result.Count);
            Assert.IsNotNull(result.FirstOrDefault(x => x == nodes[1]));
            Assert.IsNotNull(result.FirstOrDefault(x => x == nodes[2]));
		}


	}
}